package com.woniu.dao;

import com.woniu.dto.ServerToServerMenu;
import com.woniu.dto.SubscribeToServer;
import com.woniu.pojo.ServerMenu;
import com.woniu.pojo.ServerSubscribe;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.data.annotation.Id;

import java.util.List;

public interface ServerSubscribeMapper {
    int deleteByPrimaryKey(Long id);

    int insert(ServerSubscribe record);

    int insertSelective(ServerSubscribe record);

    ServerSubscribe selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(ServerSubscribe record);

    int updateByPrimaryKey(ServerSubscribe record);

    @Update("update server_subscribe set status=0 where id=#{id} ")
    int updateByDBId(Long id);

    @Select("select * from server_subscribe sb right join servers s on sb.server_id=s.id where user_id = #{id} and status=1")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(column = "server_id", property = "servers", one = @One(select = "getServerToserverMenu", fetchType = FetchType.EAGER))
    })
    List<SubscribeToServer> getMySub(Long id);

    @Select("select * from servers s right join server_menu sm on s.server_menu_id = sm.id where s.id=#{ser_id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(column = "server_menu_id", property = "serverMenu", one = @One(select = "getServerMenu", fetchType = FetchType.EAGER))
    })
    ServerToServerMenu getServerToserverMenu(Long ser_id);

    @Select("select * from server_menu where id=#{server_menu_id}")
    ServerMenu getServerMenu(Long server_menu_id);
}